<template>
  <div class="flex items-center">
    <el-select
      :model-value="modelValue"
      placeholder="请选择图标"
      @change="handleChange"
      filterable
    >
      <el-option v-for="item in icons" :key="item" :label="item" :value="item">
        <div class="flex items-center justify-between">
          <el-icon>
            <component :is="item" />
          </el-icon>
          <span class="text-gray-500">{{ item }}</span>
        </div>
      </el-option>
    </el-select>
    <el-icon :size="20" v-if="modelValue" class="ml-2">
      <component :is="modelValue" />
    </el-icon>
  </div>
</template>

<script setup>
import * as iconList from '@element-plus/icons-vue'
import { ref } from 'vue'
defineProps({
  modelValue: String
})
const icons = ref(Object.keys(iconList))
const emit = defineEmits(['update:modelValue'])
const handleChange = icon => {
  emit('update:modelValue', icon)
}
</script>

<style lang="scss" scoped></style>
